package com.pwt.common;

import com.pwt.entity.AcceptanceLimit;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

import java.util.Collection;
import java.util.List;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/8/31
 */
@Data
@NoArgsConstructor
@Schema(description = "分页数据模型")
public class ResultPage<T> {

    @Schema(description = "响应对象")
    private Collection<T> data;

    @Schema(description = "当前页")
    private Integer currentPage;

    @Schema(description = "每页条数")
    private Integer pageSize;

    @Schema(description = "总页数")
    private Integer totalPage;

    @Schema(description = "总条数")
    private Long totalRow;

    public ResultPage(Page<T> page){
        this.data = page.getContent();
        this.currentPage = page.getNumber();
        this.pageSize = page.getSize();
        this.totalPage = page.getTotalPages();
        this.totalRow = page.getTotalElements();
    }

    public ResultPage(Collection<T> data, Integer currentPage, Integer pageSize, Long totalRow) {
        this.data = data;
        this.currentPage = currentPage+1;
        this.pageSize = pageSize;
        this.totalPage = (int)Math.ceil(Double.parseDouble(totalRow.toString())/Double.parseDouble(pageSize.toString()));
        this.totalRow = totalRow;
    }
}
